//
//  OnlyIntegerValueFormatter.swift
//  OneMeeting
//
//  Created by zhangheng on 2019/8/26.
//  Copyright © 2019 www.zhangheng.com. All rights reserved.
//

import Foundation

class OnlyIntegerValueFormatter: NumberFormatter {
    override func isPartialStringValid(_ partialString: String, newEditingString newString: AutoreleasingUnsafeMutablePointer<NSString?>?, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool {
        
        var nonDecimalCharacters:CharacterSet?;
        if nonDecimalCharacters == nil {
            nonDecimalCharacters = NSCharacterSet.decimalDigits.inverted
        }
        if partialString.count == 0 {
            return true
        }else if partialString.rangeOfCharacter(from: nonDecimalCharacters!)?.isEmpty == true {
            return false
        }
        
        return true
    }
    
}
